package com.xbdun.web.bmp.service.scheduling;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xbdun.comweb.bmp.util.UserInfoUtil;
import com.xbdun.facade.validatebmp.constant.DubboValidateBmpConst;
import com.xbdun.facade.validatebmp.request.SimpleMailMessageRequest;
import com.xbdun.facade.validatebmp.service.email.EmailFacade;

import lombok.extern.slf4j.Slf4j;

/**
* @ClassName: UserAuthScheduler
* @Description: 定时器，定时刷新本地项目菜单
* @author zhanggt 360730440@qq.com
* @date 2017年5月12日 下午1:31:10
*/
@Component
@Slf4j
public class UserAuthScheduler {
	@Value("${xbdun.platfrom.code}")
	private int platCode;//平台Code
	@Value("${spring.application.name}")
	private String platName;
	@Reference(registry=DubboValidateBmpConst.REGISTRYS)
	EmailFacade emailFacade;//发送邮件
	//重新查询本地缓存系统菜单
	@Scheduled(cron="${xbdun.platfrom.code.scheduTime}")
    public void initPlatform() {
		try{
			//重新刷新本地服务菜单
			UserInfoUtil.getIUserAuth().initPlatform(platCode);
		}catch(Exception e){
			try{
				SimpleMailMessageRequest reqeust =  new SimpleMailMessageRequest();
				reqeust.setSubject("平台:"+platName+",编号:["+platCode+"]同步菜单异常");
				reqeust.setText(e.getMessage());
				emailFacade.sendSimpleMailMessage(reqeust);
			}catch(Exception ex){log.error("发送邮件失败",ex);}
		}
    }
}
